--
-- Author: shunguo.chen
-- Date: 2017-11-28 13:50:12
--
-- MountSpeedView  骑术界面

local fileName = string.getModeName(...)
local MountCorePropStarView = class(fileName, app.mvc.ViewBase)
local MountCorePropStarRender = import(".renders.MountCorePropStarRender")


MountCorePropStarView.VIEW_ROOT_RES = Res.MountCorePorpStar

function MountCorePropStarView:init()
    display.nodeRemoveForNotHit(self._ui.Panel, function()
        executeFunc(self.closeView, self)
    end)
    self._ui["Panel/Button_close"]:addClickEventListener(function()
        executeFunc(self.closeView, self)
    end)
    display.setCascadeOpacityEnabled(self._ui["Panel/Panel_content/Panel_next"], true)


    self._render1 = MountCorePropStarRender.create(self._ui["Panel/Panel_content/node_1"])
    self._render2 = MountCorePropStarRender.create(self._ui["Panel/Panel_content/Panel_next/node_2"])
end

function MountCorePropStarView:refresh(starNum)
    local rows = GD:queryCorePorpExtraValues(UD:getClass())
    local curStarConfig = nil
    local nextStarConfig = nil

    for k , v in ipairs(rows) do
        local t = tonumber(v.starNum or 0)
        if starNum < t then
            curStarConfig = rows[k-1]
            nextStarConfig = v
            break
        end
    end

    if not curStarConfig then
        curStarConfig = rows[#rows]
    end

    if curStarConfig then
        self._render1:setData({config = curStarConfig, starNum = starNum})
    end
   
    if nextStarConfig then
        self._render2:setData({config = nextStarConfig, starNum = nextStarConfig.starNum, lastConfig = curStarConfig})
        self._render2:setTitle(L("MountCorePropTitle2"))
        self._ui["Panel/Panel_content/Panel_max"]:setVisible(false)
        self._ui["Panel/Panel_content/Panel_next"]:setVisible(true)
        self._ui["Panel/Panel_content/Panel_next/text"]:setString(L("MountCorePropBottom"))
    else
        self._ui["Panel/Panel_content/Panel_max"]:setVisible(true)
        self._ui["Panel/Panel_content/Panel_next"]:setVisible(false)
        self._ui["Panel/Panel_content/Panel_max/text"]:setString(L("MountCorePropMax"))
    end

    self._render1:setTitle(L("MountCorePropTitle1"))
    
end

return MountCorePropStarView